<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="合同编号" prop="contractNumber">
        <el-input
          v-model="queryParams.contractNumber"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="归档编号" prop="archiveNumber">
        <el-input
          v-model="queryParams.archiveNumber"
          placeholder="请输入归档编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--el-form-item label="合同拟定方" prop="contractDraftParty">
        <el-select v-model="queryParams.contractDraftParty" placeholder="请选择合同拟定方" clearable>
          <el-option
            v-for="dict in dict.type.contract_draft_party"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item-->
      <el-form-item label="合同状态" prop="contractStatus">
        <el-select v-model="queryParams.contractStatus" placeholder="请选择合同状态" clearable style="width: 205px">
          <el-option
            v-for="dict in dict.type.contract_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="甲方" prop="firstPartyName">
        <el-input
          v-model="queryParams.firstPartyName"
          placeholder="请输入甲方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--el-form-item label="甲方地址" prop="firstPartyAddress">
        <el-input
          v-model="queryParams.firstPartyAddress"
          placeholder="请输入甲方地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="甲方业务员" prop="firstPartySalesman">
        <el-input
          v-model="queryParams.firstPartySalesman"
          placeholder="请输入甲方业务员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="甲方业务电话" prop="firstPartyMobile">
        <el-input
          v-model="queryParams.firstPartyMobile"
          placeholder="请输入甲方业务电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="甲方结算人" prop="firstPartyReckoner">
        <el-input
          v-model="queryParams.firstPartyReckoner"
          placeholder="请输入甲方结算人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="甲方结算电话" prop="firstReckonerMobile">
        <el-input
          v-model="queryParams.firstReckonerMobile"
          placeholder="请输入甲方结算电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item-->
      <el-form-item label="乙方" prop="secondPartyName">
        <el-input
          v-model="queryParams.secondPartyName"
          placeholder="请输入乙方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--el-form-item label="乙方地址" prop="secondPartyAddress">
        <el-input
          v-model="queryParams.secondPartyAddress"
          placeholder="请输入乙方地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乙方业务员" prop="secondPartySalesman">
        <el-input
          v-model="queryParams.secondPartySalesman"
          placeholder="请输入乙方业务员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乙方业务电话" prop="secondPartyMobile">
        <el-input
          v-model="queryParams.secondPartyMobile"
          placeholder="请输入乙方业务电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乙方结算人" prop="secondPartyReckoner">
        <el-input
          v-model="queryParams.secondPartyReckoner"
          placeholder="请输入乙方结算人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乙方结算电话" prop="secondReckonerMobile">
        <el-input
          v-model="queryParams.secondReckonerMobile"
          placeholder="请输入乙方结算电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item-->
      <el-form-item label="合同日期">
        <el-date-picker
          v-model="daterangeContractDate"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="协议开始">
        <el-date-picker
          v-model="daterangeArgeementBeginDate"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="协议结束">
        <el-date-picker
          v-model="daterangeArgeementEndDate"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <!--el-form-item label="运输货物" prop="transportGoods">
        <el-select v-model="queryParams.transportGoods" placeholder="请选择运输货物" clearable>
          <el-option
            v-for="dict in dict.type.goods_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="运输方式" prop="transportMode">
        <el-input
          v-model="queryParams.transportMode"
          placeholder="请输入运输方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结算计价" prop="settlementPriceMode">
        <el-select v-model="queryParams.settlementPriceMode" placeholder="请选择结算计价" clearable>
          <el-option
            v-for="dict in dict.type.price_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="结算方式" prop="settlementMode">
        <el-select v-model="queryParams.settlementMode" placeholder="请选择结算方式" clearable>
          <el-option
            v-for="dict in dict.type.settlement_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="含仓储费" prop="containStorageFee">
        <el-select v-model="queryParams.containStorageFee" placeholder="请选择含仓储费" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input
          v-model="queryParams.remark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="园区代码" prop="parkCode">
        <el-input
          v-model="queryParams.parkCode"
          placeholder="请输入园区代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item-->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['contracts:contract:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['contracts:contract:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['contracts:contract:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['contracts:contract:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" @computeTable="computeTableHeight"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange" border :height="tableHeight" :row-style="{height:'35px'}" :cell-style="{padding:'0px'}">
      <el-table-column type="selection" width="45" align="center" />
      <el-table-column type="index" prop="" width="55" label="序号" align="center" >
        <template slot-scope="scope">
          <span>{{ scope.$index+1 +(queryParams.pageNum-1)*queryParams.pageSize }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100%">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['contracts:contract:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['contracts:contract:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
      <!--el-table-column label="合同ID" align="center" prop="contractId" /-->
      <el-table-column label="合同编号" align="center" prop="contractNumber" width="150" />
      <el-table-column label="归档编号" align="center" prop="archiveNumber" width="150" :show-overflow-tooltip="true" />
      <el-table-column label="合同拟定方" align="center" prop="contractDraftParty" width="100%" />
      <el-table-column label="合同状态" align="center" prop="contractStatus" />
      <el-table-column label="甲方" align="center" prop="firstPartyName" width="240" :show-overflow-tooltip="true" />
      <el-table-column label="甲方地址" align="center" prop="firstPartyAddress" width="300" :show-overflow-tooltip="true" />
      <el-table-column label="甲方业务员" align="center" prop="firstPartySalesman" width="100%" />
      <el-table-column label="甲方业务电话" align="center" prop="firstPartyMobile" width="110" />
      <el-table-column label="甲方结算人" align="center" prop="firstPartyReckoner" width="110" />
      <el-table-column label="甲方结算电话" align="center" prop="firstReckonerMobile" width="110" />
      <el-table-column label="乙方" align="center" prop="secondPartyName" width="240" :show-overflow-tooltip="true" />
      <el-table-column label="乙方地址" align="center" prop="secondPartyAddress"  width="300" :show-overflow-tooltip="true" />
      <el-table-column label="乙方业务员" align="center" prop="secondPartySalesman" width="100%" />
      <el-table-column label="乙方业务电话" align="center" prop="secondPartyMobile" width="110" />
      <el-table-column label="乙方结算人" align="center" prop="secondPartyReckoner" width="100%" />
      <el-table-column label="乙方结算电话" align="center" prop="secondReckonerMobile" width="110" />
      <el-table-column label="合同日期" align="center" prop="contractDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="协议开始日期" align="center" prop="argeementBeginDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.argeementBeginDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="协议结束日期" align="center" prop="argeementEndDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.argeementEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="运输货物" align="center" prop="transportGoods" />
      <el-table-column label="运输方式" align="center" prop="transportMode" />
      <el-table-column label="结算计价" align="center" prop="settlementPriceMode" />
      <el-table-column label="结算方式" align="center" prop="settlementMode" />
      <el-table-column label="含仓储费" align="center" prop="containStorageFee" />
      <el-table-column label="备注" align="center" prop="remark" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="合同扫描件" align="center" prop="contractScanDocument" width="140" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="handleDownload(scope.row)"
            :disabled="scope.row.contractScanDocument == null || scope.row.contractScanDocument == ''"
          >下载</el-button>
        </template>
      </el-table-column>
      <el-table-column label="营业执照" align="center" prop="businessLicensePicture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.businessLicensePicture" :width="50" :height="25"/>
        </template>
      </el-table-column>
      <el-table-column label="其他照片" align="center" prop="otherPicture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.otherPicture" :width="50" :height="25"/>
        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改合同信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <!--el-form-item label="合同编号" prop="contractNumber">
          <el-input v-model="form.contractNumber" placeholder="请输入合同编号" clearable />
        </el-form-item-->
        <el-form-item label="归档编号" prop="archiveNumber">
          <el-input v-model="form.archiveNumber" placeholder="请输入归档编号" clearable />
        </el-form-item>
        <el-form-item label="合同拟定方" prop="contractDraftParty">
          <el-select v-model="form.contractDraftParty" placeholder="请选择合同拟定方" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.contract_draft_party"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="合同状态" prop="contractStatus">
          <el-select v-model="form.contractStatus" placeholder="请选择合同状态" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.contract_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="甲方" prop="firstPartyName">
          <el-input v-model="form.firstPartyName" placeholder="请输入甲方" clearable />
        </el-form-item>
        <el-form-item label="甲方地址" prop="firstPartyAddress">
          <el-input v-model="form.firstPartyAddress" placeholder="请输入甲方地址" clearable />
        </el-form-item>
        <el-form-item label="甲方业务员" prop="firstPartySalesman">
          <el-input v-model="form.firstPartySalesman" placeholder="请输入甲方业务员" clearable />
        </el-form-item>
        <el-form-item label="甲方业务电话" prop="firstPartyMobile">
          <el-input v-model="form.firstPartyMobile" placeholder="请输入甲方业务电话" clearable />
        </el-form-item>
        <el-form-item label="甲方结算人" prop="firstPartyReckoner">
          <el-input v-model="form.firstPartyReckoner" placeholder="请输入甲方结算人" clearable />
        </el-form-item>
        <el-form-item label="甲方结算电话" prop="firstReckonerMobile">
          <el-input v-model="form.firstReckonerMobile" placeholder="请输入甲方结算电话" clearable />
        </el-form-item>
        <el-form-item label="乙方" prop="secondPartyName">
          <el-input v-model="form.secondPartyName" placeholder="请输入乙方" clearable />
        </el-form-item>
        <el-form-item label="乙方地址" prop="secondPartyAddress">
          <el-input v-model="form.secondPartyAddress" placeholder="请输入乙方地址" clearable />
        </el-form-item>
        <el-form-item label="乙方业务员" prop="secondPartySalesman">
          <el-input v-model="form.secondPartySalesman" placeholder="请输入乙方业务员" clearable />
        </el-form-item>
        <el-form-item label="乙方业务电话" prop="secondPartyMobile">
          <el-input v-model="form.secondPartyMobile" placeholder="请输入乙方业务电话" clearable />
        </el-form-item>
        <el-form-item label="乙方结算人" prop="secondPartyReckoner">
          <el-input v-model="form.secondPartyReckoner" placeholder="请输入乙方结算人" clearable />
        </el-form-item>
        <el-form-item label="乙方结算电话" prop="secondReckonerMobile">
          <el-input v-model="form.secondReckonerMobile" placeholder="请输入乙方结算电话" clearable />
        </el-form-item>
        <el-form-item label="合同日期" prop="contractDate">
          <el-date-picker clearable
            v-model="form.contractDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择合同日期"
            style="width: 340px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="协议开始日期" prop="argeementBeginDate">
          <el-date-picker clearable
            v-model="form.argeementBeginDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择协议开始日期"
            style="width: 340px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="协议结束日期" prop="argeementEndDate">
          <el-date-picker clearable
            v-model="form.argeementEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择协议结束日期"
            style="width: 340px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="运输货物" prop="transportGoods">
          <el-select v-model="form.transportGoods" placeholder="请选择运输货物" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.goods_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="运输方式" prop="transportMode">
          <el-input v-model="form.transportMode" placeholder="请输入运输方式" clearable />
        </el-form-item>
        <el-form-item label="结算计价" prop="settlementPriceMode">
          <el-select v-model="form.settlementPriceMode" placeholder="请选择结算计价" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.price_mode"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结算方式" prop="settlementMode">
          <el-select v-model="form.settlementMode" placeholder="请选择结算方式" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.settlement_mode"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="含仓储费" prop="containStorageFee">
          <el-select v-model="form.containStorageFee" placeholder="请选择含仓储费" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" clearable />
        </el-form-item>
        <el-form-item label="合同扫描件" prop="contractScanDocument">
          <file-upload v-model="form.contractScanDocument"/>
        </el-form-item>
        <el-form-item label="营业执照" prop="businessLicensePicture">
          <image-upload v-model="form.businessLicensePicture" :limit="1"/>
        </el-form-item>
        <el-form-item label="其他照片" prop="otherPicture">
          <image-upload v-model="form.otherPicture" :limit="1"/>
        </el-form-item>
        <!--el-form-item label="园区代码" prop="parkCode">
          <el-input v-model="form.parkCode" placeholder="请输入园区代码" clearable />
        </el-form-item-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContract, getContract, delContract, addContract, updateContract } from "@/api/contracts/contract";

export default {
  name: "Contract",
  dicts: ['contract_draft_party', 'sys_yes_no', 'price_mode', 'settlement_mode', 'contract_status', 'goods_type'],
  data() {
    return {
      // 定义列表高度
      tableHeight: 430,
      // 定义查询高度
      queryHeight: 200,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 合同信息表格数据
      contractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 园区代码时间范围
      daterangeContractDate: [],
      // 园区代码时间范围
      daterangeArgeementBeginDate: [],
      // 园区代码时间范围
      daterangeArgeementEndDate: [],
      // 园区代码时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractNumber: null,
        archiveNumber: null,
        contractDraftParty: null,
        contractStatus: null,
        firstPartyName: null,
        firstPartyAddress: null,
        firstPartySalesman: null,
        firstPartyMobile: null,
        firstPartyReckoner: null,
        firstReckonerMobile: null,
        secondPartyName: null,
        secondPartyAddress: null,
        secondPartySalesman: null,
        secondPartyMobile: null,
        secondPartyReckoner: null,
        secondReckonerMobile: null,
        contractDate: null,
        argeementBeginDate: null,
        argeementEndDate: null,
        transportGoods: null,
        transportMode: null,
        settlementPriceMode: null,
        settlementMode: null,
        containStorageFee: null,
        remark: null,
        contractScanDocument: null,
        businessLicensePicture: null,
        otherPicture: null,
        parkCode: null,
        createBy: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        contractNumber: [
          { required: true, message: "合同编号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    this.$nextTick(() =>{
      // 根据浏览器高度设置初始高度 - 按钮行高度28 - 页码行高度28 - （面包屑+TAB行）高度160
      this.queryHeight = this.$refs.queryForm.$el.offsetHeight;
      this.tableHeight = window.innerHeight - this.$refs.queryForm.$el.offsetHeight - 28 - 28 - 160;
      // 监听浏览器高度变化，改变表格高度
      window.onresize = () =>{
        this.tableHeight = window.innerHeight - this.$refs.queryForm.$el.offsetHeight - 28 - 28 - 160;
      }
    })
  },
  methods: {
    /** 查询合同信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeContractDate && '' != this.daterangeContractDate) {
        this.queryParams.params["beginContractDate"] = this.daterangeContractDate[0];
        this.queryParams.params["endContractDate"] = this.daterangeContractDate[1];
      }
      if (null != this.daterangeArgeementBeginDate && '' != this.daterangeArgeementBeginDate) {
        this.queryParams.params["beginArgeementBeginDate"] = this.daterangeArgeementBeginDate[0];
        this.queryParams.params["endArgeementBeginDate"] = this.daterangeArgeementBeginDate[1];
      }
      if (null != this.daterangeArgeementEndDate && '' != this.daterangeArgeementEndDate) {
        this.queryParams.params["beginArgeementEndDate"] = this.daterangeArgeementEndDate[0];
        this.queryParams.params["endArgeementEndDate"] = this.daterangeArgeementEndDate[1];
      }
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        contractId: null,
        contractNumber: null,
        archiveNumber: null,
        contractDraftParty: null,
        contractStatus: null,
        firstPartyName: null,
        firstPartyAddress: null,
        firstPartySalesman: null,
        firstPartyMobile: null,
        firstPartyReckoner: null,
        firstReckonerMobile: null,
        secondPartyName: null,
        secondPartyAddress: null,
        secondPartySalesman: null,
        secondPartyMobile: null,
        secondPartyReckoner: null,
        secondReckonerMobile: null,
        contractDate: null,
        argeementBeginDate: null,
        argeementEndDate: null,
        transportGoods: null,
        transportMode: null,
        settlementPriceMode: null,
        settlementMode: null,
        containStorageFee: null,
        remark: null,
        contractScanDocument: null,
        businessLicensePicture: null,
        otherPicture: null,
        dataRealm: null,
        parkCode: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeContractDate = [];
      this.daterangeArgeementBeginDate = [];
      this.daterangeArgeementEndDate = [];
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.contractId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加合同信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const contractId = row.contractId || this.ids
      getContract(contractId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改合同信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.contractId != null) {
            updateContract(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContract(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const contractIds = row.contractId || this.ids;
      this.$modal.confirm('是否确认删除合同信息编号为"' + contractIds + '"的数据项？').then(function() {
        return delContract(contractIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('contracts/contract/export', {
        ...this.queryParams
      }, `contract_${new Date().getTime()}.xlsx`)
    },
    computeTableHeight(){
      if( this.showSearch==true ){
        this.tableHeight = window.innerHeight - this.queryHeight - 28 - 28 - 160;
      } else {
        this.tableHeight = window.innerHeight - 28 - 28 - 160;
      }
    },
    handleDownload(row) {
      //console.log('handleDownload, ' + process.env.VUE_APP_BASE_API);
      //const resource = "/profile/upload/2024/09/30/20240930134919A002.jpg";
      //this.$download.resource(resource, false);
      //const name = "4a8a6401-6892-4642-be19-abb5f760cc65.xlsx";
      //const isDelete = true;
      //this.$download.name(name, false);
      // 根据地址保存文件 http://localhost:8080
      const url = process.env.VUE_APP_BASE_API + row.contractScanDocument;
      const filename = `合同下载_${this.parseTime(new Date(), '{y}{m}{d}_{h}{i}')}`;
      if(row.contractScanDocument) {
        this.$download.saveAs(url, filename);
      } else {
        this.$modal.msgError("没有合同扫描件");
      }
    },
  }
};
</script>
